package org.design.controller;

import lombok.extern.slf4j.Slf4j;
import org.design.log.annotation.ApiLog;
import org.design.repeat.annotation.RepeatSubmit;
import org.design.serial.SerialService;
import org.design.serial.dto.GenSerialParam;
import org.design.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TestController
 *
 * @author 樊温军
 * @date 2025/6/16 上午9:59
 */
@Slf4j
@Controller
@RequestMapping("/test")
public class TestController {

    private SerialService serialService;

    @Autowired
    public void setSerialService(SerialService serialService) {
        this.serialService = serialService;
    }

    /**
     * 生成流水号
     *
     * @param genSerialParam 生成流水号参数
     * @return 生成的流水号
     */
    @RepeatSubmit
    @ApiLog("生成流水号")
    @PostMapping("/genSerialNumber")
    @ResponseBody
    public R<String> genSerialNumber(@RequestBody GenSerialParam genSerialParam) {
        String serialNumber = serialService.generateSerialNumber(genSerialParam);
        log.info("serialNumber: {}", serialNumber);
        return R.ok(serialNumber);
    }

}
